package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.bean.CallbackBean;

import java.util.List;

public class CallBackAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<CallbackBean> mCallbackBean;
    private String TAG="AgentAdapter";
    public CallBackAdapter(Context context, List<CallbackBean> maxCallbackBeanDatas){
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mCallbackBean = maxCallbackBeanDatas;
    }

    @Override
    public int getCount() {
        return mCallbackBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mCallbackBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.callback_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.mCall_name = convertView.findViewById(R.id.callback_name);
            viewHolder.mCall_sn = convertView.findViewById(R.id.callbacksn_number);
            viewHolder.mCall_stat = convertView.findViewById(R.id.callback_stat);
            viewHolder.mCall_select = convertView.findViewById(R.id.callback_select);
             convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        CallbackBean agentbean = mCallbackBean.get(position);
        viewHolder.mCall_name.setText(agentbean.getMerName());
        viewHolder.mCall_sn.setText(agentbean.getSn());
        viewHolder.mCall_stat.setText(agentbean.getStart());
        if(mCallbackBean.get(position).isChecked()){
            viewHolder.mCall_select.setImageResource(R.drawable.cb_true);
        }else{
            viewHolder.mCall_select.setImageResource(R.drawable.cb_fase);
        }

        return convertView;
    }


    public static class ViewHolder{
        TextView mCall_name;
        TextView mCall_sn;
        TextView mCall_stat;
        ImageView mCall_select;
    }


}
